package dr.server.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

/**
 * 信息是否发送  白名单/黑名单/开关  限制
 */
@Slf4j
@Service
public class AstrictService {

    @Autowired
    private Environment env;

    /**
     * @param to 接收人员
     * @return true发行  false拒绝
     */
    public Boolean check(String type, String to){
        String isSwitch = env.getProperty("astrict.smsNum"+type+".isSwitch","");
        if("true".equals(isSwitch)){
            //验证白名单 如果直接符合  直接通过
            String blacklist = env.getProperty("astrict.smsNum"+type+".blacklist","");
            String[] blacklistArray = blacklist.split(",");
            for (String s : blacklistArray) {
                if(!"5".equals(type) && to.equals(s)){
                    return true;
                }
                //增对 匹配人员id
                else if(to.equals(s)) {
                    return true;
                }
            }

            //验证黑名单
            String whiteListlist = env.getProperty("astrict.smsNum"+type+".whiteList","");
            String[] whiteListArray = whiteListlist.split(",");
            Boolean result=true;
            for (String s : whiteListArray) {
               if(!"3".equals(type) && to.equals(s)){
                   result=false;
               }
               //增对于极光推送
               else if(to.contains(s)){
                   result=false;
               }
               if(!result){
                   return false;
               }
            }
        }
        return false;
    }

}
